using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LaserOnAttack:MonoBehaviour {

	[SerializeField] ProjectileData laserProjectile;
	private void Start() {
		if(!GetComponent<Humanoid>()) return;
		Mob._LaserOnAttack core = gameObject.AddComponent<Mob._LaserOnAttack>();
		core.laserProjectile=laserProjectile;
	}

}


public partial class Mob {

	public class _LaserOnAttack:MonoBehaviour {

		Projectile laserObject;
		Humanoid mob;

		WeaponSlot lastWeapon;

		public ProjectileData laserProjectile;

		private void Start() {
			mob=GetComponent<Humanoid>();
		}

		private void FixedUpdate() {

			if(mob==null) return;

			if(mob.currentState==mob.StateAttack) {

				if(!laserObject||!laserObject.isActiveAndEnabled) {
					lastWeapon=mob.activeWeapon;
					laserObject=lastWeapon.weapon.ShootSingleProjectile(
						lastWeapon.muzzle.position,
						Angle.FromQuaternion(lastWeapon.muzzle.rotation),
						laserProjectile,
						new Dictionary<int,int>()
					);
				}

				if(lastWeapon!=null&&lastWeapon.isActiveAndEnabled) {
					if(laserObject&&laserObject.isActiveAndEnabled) laserObject.gameObject.SetActive(false);
					lastWeapon=mob.activeWeapon;
					laserObject=lastWeapon.weapon.ShootSingleProjectile(
						lastWeapon.muzzle.position,
						Angle.FromQuaternion(lastWeapon.muzzle.rotation),
						laserProjectile,
						new Dictionary<int,int>()
					);
				}


			} else {
				if(laserObject&&laserObject.isActiveAndEnabled) {
					laserObject.gameObject.SetActive(false);
				}
			}
		}

	}

}